﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using perfume.Models.DB;
using perfume.Models.ViewModels;

namespace perfume.Models.ObjectManager
{
    public class UserManager
    {
        private perfume_dbEntities per_db = new perfume_dbEntities();
        public void Add(UserView userview)
        {

            DB.user user = new DB.user();
            user.username = userview.UserName;
            user.password = userview.Password;
            user.name = userview.Name;
            user.address = userview.Address;
            user.phone_number = userview.PhoneNumber;
            user.role_id = 2;
            per_db.AddTousers(user);
            per_db.SaveChanges();
        }

        public bool IsUserLoginIDExist(string userLogIn)
        {
            return (from o in per_db.users where o.username == userLogIn select o).Any();
        }

        public string GetUserPassword(string userLogIn)
        {
            var user = from o in per_db.users where o.username == userLogIn select o;
            if (user.ToList().Count > 0)
            {
                
                return user.First().password;
            }
            else
                return string.Empty;
        }

        public string GetUserName(string userLogIn)
        {
            var user = from o in per_db.users where o.username == userLogIn select o;
            if (user.ToList().Count > 0)
            {

                return user.First().username;
            }
            else
                return string.Empty;
        }

    }
}